import modules.mapper.EmployeeMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;

public class Hi {
    public static void main(String[] args) throws IOException {
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactory() ;
        SqlSession sqlSession = sqlSessionFactory.openSession(true);//可以自动提交
        try{
            EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
            List list = employeeMapper.getEmployeeById(1) ;
            Iterator iterator = list.iterator() ;
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
            sqlSession.commit();
        }finally {
            sqlSession.close();
        }
    }
    public static SqlSessionFactory getSqlSessionFactory () throws IOException {
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            return new SqlSessionFactoryBuilder().build(inputStream);
        }
    }


